package com.hwhhhh.mygrad.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.hwhhhh.mygrad.R;

import java.util.List;

public class SearchHistoryAdapter extends RecyclerView.Adapter<SearchHistoryAdapter.SearchHistoryHolder> {
    private List<String> data;

    public SearchHistoryAdapter(List<String> data) {
        this.data = data;
    }

    @NonNull
    @Override
    public SearchHistoryHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_search_history, parent, false);
        return new SearchHistoryHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull SearchHistoryHolder holder, int position) {
        holder.text.setText(data.get(position));
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    class SearchHistoryHolder extends RecyclerView.ViewHolder {
        TextView text;

        public SearchHistoryHolder(@NonNull View itemView) {
            super(itemView);
            text = itemView.findViewById(R.id.tv_search_content);
        }
    }
}
